Skip to content

Enable trim and AOT analyzers for selected library tests#128355

Open
Copilot wants to merge 9 commits into
mainfrom
copilot/fix-trim-aot-warnings
Open

Enable trim and AOT analyzers for selected library tests#128355
Copilot wants to merge 9 commits into
mainfrom
copilot/fix-trim-aot-warnings

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

Description

Several library test projects suppressed trim/AOT analyzer warnings by disabling the analyzers at the project level. This change enables the analyzers for the selected test projects where appropriate and replaces broad suppressions with targeted fixes or narrow warning pragmas at known test-only reflection and dynamic-code sites.

  • Removed the dotnet/runtime#126862 analyzer-disable blocks from the selected test projects, while leaving Microsoft.Extensions.HostFactoryResolver.Tests disabled for separate follow-up because enabling it would require product changes.
  • Replaced avoidable warnings with analyzer-friendly code, such as DiagnosticMethodInfo, Enum.GetValues<TEnum>(), LINQ-based collection conversion, and source-project references where applicable.
  • Added .NET Framework-compatible fallbacks or source-linked attributes where analyzer-friendly APIs and annotations are unavailable in net481 test builds.
  • Updated System.Threading.RateLimiting.Tests to reference the source project with SkipUseReferenceAssembly="true" and avoid local reflection suppressions.
  • Marked reflection-heavy test helpers with trim annotations where appropriate, including source generator structural equality helpers and QUIC interop reset helpers.
  • Propagated required DynamicallyAccessedMembers annotations through the WinHttpHandler test marshal shim.
  • Removed dead GetStateMachineData.Describe diagnostic code and its remaining caller now that it no longer works with runtime async.
  • Added narrow #pragma warning disable/restore scopes only for remaining emitted IL warnings that require reflection, dynamic code, or unsupported trim/AOT analysis patterns.
  • Added explanatory context to remaining targeted suppressions, including issue links or rationale for why the test-only operation is safe.

Copilot AI and others added 2 commits May 19, 2026 02:37
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5977beb1-58f4-4a75-9a1c-02ff1bb17294

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5977beb1-58f4-4a75-9a1c-02ff1bb17294

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI self-assigned this May 19, 2026
Copilot AI review requested due to automatic review settings May 19, 2026 03:06
Copilot AI review requested due to automatic review settings May 19, 2026 03:06
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/libraries/System.IO.Packaging/tests/PartPieceTests.cs Outdated
Comment thread src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs Outdated
Comment thread src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs Outdated
Comment thread src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs Outdated
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5a0b0c7b-d13e-4936-8392-ff08d859bc72

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 19, 2026 04:24
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5a0b0c7b-d13e-4936-8392-ff08d859bc72

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>

// Try to get the StateMachine field from the AsyncStateMachineBox<>. If we can't,
// just print out the details we can and bail.
#pragma warning disable IL2075
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we're using runtime-async I wonder if this is just dead code

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this looks like it will no longer do what is says with runtime async. We should delete GetStateMachineData.Describe method and the callers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7d17a32 by deleting GetStateMachineData.Describe and removing its remaining caller.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7d17a32 by deleting GetStateMachineData.Describe and updating the Watchdog caller.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already addressed in 7d17a32 by deleting GetStateMachineData.Describe and removing its remaining caller.

Copy link
Copy Markdown
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs Outdated

// Try to get the StateMachine field from the AsyncStateMachineBox<>. If we can't,
// just print out the details we can and bail.
#pragma warning disable IL2075
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this looks like it will no longer do what is says with runtime async. We should delete GetStateMachineData.Describe method and the callers.

Comment thread src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs Outdated
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/087bc9c5-a2a7-4eea-becd-4a9625ddce15

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 05:27
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/087bc9c5-a2a7-4eea-becd-4a9625ddce15

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 05:30
Copilot AI requested a review from MichalStrehovsky May 21, 2026 05:33
Comment thread src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs Outdated
Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 21, 2026 06:14
@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review May 21, 2026 06:15
Copy link
Copy Markdown
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dotnet/illink could someone have a look please? From my side the main open question is what to do with #128355 (comment). I asked copilot to delete it. Maybe we could also just pragma suppress it and file a bug on the networking team to figure out what they want to do with it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables trim/AOT analyzers for a set of library test projects by removing project-level analyzer disables and addressing resulting warnings with targeted code changes (e.g., analyzer-friendly APIs) and narrowly-scoped suppressions/annotations at test-only reflection/dynamic-code sites.

Changes:

  • Removed project-level EnableTrimAnalyzer / EnableAotAnalyzer disables from selected test projects.
  • Replaced broad suppressions with targeted fixes, Requires* annotations, and narrow #pragma warning disable/restore scopes where reflection/dynamic code is test-required.
  • Updated a few tests/helpers to be more analyzer-friendly (e.g., Enum.GetValues<TEnum>(), DiagnosticMethodInfo, LINQ conversions, and source-project references where needed).

Reviewed changes

Copilot reviewed 52 out of 52 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/libraries/System.Threading.RateLimiting/tests/System.Threading.RateLimiting.Tests.csproj Re-enables trim analyzer and adjusts test project reference settings.
src/libraries/System.Threading.RateLimiting/tests/PartitionedRateLimiterTests.cs Updates calls to reflection-based helper with explicit generic arguments.
src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs Refactors reflection helper used to invoke DefaultPartitionedRateLimiter heartbeat under analyzers.
src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj Re-enables trim analyzer for Roslyn 4.4 source-gen unit tests.
src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj Re-enables trim analyzer for Roslyn 3.11 source-gen unit tests.
src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/JsonSourceGeneratorIncrementalTests.cs Adds targeted suppressions for reflection-heavy structural equality checks.
src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj Re-enables AOT analyzer for PKCS tests.
src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs Adds narrow IL3050 suppression around non-zero-lower-bound array creation.
src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs Adds narrow IL3050 suppression around non-zero-lower-bound array creation.
src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs Adds narrow IL3050 suppression around non-zero-lower-bound array creation.
src/libraries/System.Runtime/tests/System.Threading.Tasks.Extensions.Tests/System.Threading.Tasks.Extensions.Tests.csproj Re-enables trim analyzer for task extensions tests.
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj Re-enables trim analyzer for reflection invoke-interpreted tests.
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj Re-enables trim analyzer for reflection invoke-emit tests.
src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/BindingFlagsDoNotWrap.cs Adds narrow suppression for reflection pattern warning during Assembly.CreateInstance tests.
src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj Re-enables trim analyzer for RuntimeInformation tests.
src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs Adds narrow suppression for reflection-based informational logging.
src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj Re-enables trim analyzer for System.Reflection CoreCLR tests.
src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs Adds narrow suppressions for AssemblyLoadContext.LoadFromStream trimming warnings.
src/libraries/System.Runtime/tests/System.Buffers.Tests/System.Buffers.Tests.csproj Re-enables trim analyzer for System.Buffers tests.
src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs Adds narrow suppression around known-broken private reflection access in a stress test.
src/libraries/System.Runtime.Serialization.Primitives/tests/System/Runtime/Serialization/InvalidDataContractExceptionTests.cs Annotates BinaryFormatter serialization test with RequiresDynamicCode/RequiresUnreferencedCode.
src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj Re-enables trim/AOT analyzers for serialization primitives tests.
src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs Adds narrow suppression for COM-disabled reflection-only API usage.
src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System.Runtime.InteropServices.ComDisabled.Tests.csproj Re-enables trim analyzer for COM-disabled interop unit tests.
src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj Re-enables trim analyzer for ComInterfaceGenerator unit tests.
src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs Adds narrow suppression around reflection-based Type.GetType(...) usage in generated snippets.
src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj Re-enables trim analyzer for WebSockets client tests.
src/libraries/System.Net.WebSockets.Client/tests/CloseTest.Loopback.cs Adds narrow suppressions around reflection-based activation in loopback test.
src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs Replaces ArrayList-to-array conversion with LINQ-based conversion to avoid AOT warnings.
src/libraries/System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj Re-enables AOT analyzer for WebProxy tests.
src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj Re-enables AOT analyzer for System.Net.Security functional tests.
src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNegotiatedCipherSuiteTest.cs Uses Enum.GetValues<TEnum>() to avoid dynamic enum array creation warnings.
src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj Re-enables trim analyzer for QUIC functional tests.
src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs Adds trim annotations and targeted suppression for reflection-based member reset helper.
src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj Re-enables AOT analyzer for System.Net.Mail functional tests.
src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs Adds narrow IL3050 suppression around reflection-based private SendAsync invocation.
src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs Removes state-machine diagnostic printing and adjusts watchdog timer behavior.
src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj Re-enables trim analyzer for WinHttpHandler unit tests.
src/libraries/System.Management/tests/System.Management.Tests.csproj Re-enables trim/AOT analyzers for System.Management tests.
src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj Re-enables AOT analyzer for System.IO.Packaging tests.
src/libraries/System.IO.Packaging/tests/PartPieceTests.cs Adds narrow IL3050 suppression around MakeGenericType used in reflection-heavy test logic.
src/libraries/System.DirectoryServices/tests/System.DirectoryServices.Tests.csproj Re-enables trim analyzer for System.DirectoryServices tests.
src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.cs Switches to DiagnosticMethodInfo to avoid trim warnings from StackFrame.GetMethod().
src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj Re-enables trim analyzer for external container DI tests.
src/libraries/Microsoft.Extensions.Configuration/tests/Microsoft.Extensions.Configuration.Tests.csproj Re-enables trim/AOT analyzers for configuration tests.
src/libraries/Microsoft.Extensions.Configuration/tests/ConfigurationProviderTestBase.cs Adds narrow suppressions around reflection-based binder usage in tests.
src/libraries/Microsoft.Extensions.Configuration.Json/tests/Microsoft.Extensions.Configuration.Json.Tests.csproj Re-enables trim/AOT analyzers for JSON configuration tests.
src/libraries/Microsoft.Extensions.Configuration.Ini/tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj Re-enables trim/AOT analyzers for INI configuration tests.
src/libraries/Microsoft.Extensions.Configuration.CommandLine/tests/Microsoft.Extensions.Configuration.CommandLine.Tests.csproj Re-enables trim/AOT analyzers for command-line configuration tests.
src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs Adds narrow IL2026 suppression around structural reflection equality helper.
src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs Removes reflection-based Describe logic; keeps awaitable box capture helper.
src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs Adds RequiresUnreferencedCode annotation to reflection-based structural equality helper.
Comments suppressed due to low confidence (1)

src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs:40

  • Watchdog._box is assigned in UnsafeOnCompleted but is no longer read anywhere after the GetStateMachineData.Describe removal. This is likely to trigger CS0414 (assigned but its value is never used) under warnings-as-errors. Remove the field/assignment (or otherwise consume the value) to avoid introducing a build warning.
    internal class Watchdog : ICriticalNotifyCompletion
    {
        private object _box;

        private Watchdog() { }

        public static Watchdog CreateAsync()
            => new Watchdog();

        public IDisposable GetResult()
            => new WatchdogImpl();

        public Watchdog GetAwaiter() => this;
        public bool IsCompleted => false;
        public void OnCompleted(Action continuation) => UnsafeOnCompleted(continuation);
        public void UnsafeOnCompleted(Action continuation)
        {
            _box = continuation.Target;
            Task.Run(continuation);
        }

@MichalStrehovsky
Copy link
Copy Markdown
Member

@copilot build breaks

D:\a\_work\1\s\src\libraries\System.Management\tests\System\Management\ManagementObjectTests.cs(118,17): error IL2026: Using member 'System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream, Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. BinaryFormatter serialization is not trim compatible because the type of objects being processed cannot be statically discovered. [D:\a\_work\1\s\src\libraries\System.Management\tests\System.Management.Tests.csproj::TargetFramework=net11.0-windows]
D:\a\_work\1\s\src\libraries\System.Management\tests\System\Management\ManagementObjectTests.cs(121,54): error IL2026: Using member 'System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. BinaryFormatter serialization is not trim compatible because the type of objects being processed cannot be statically discovered. [D:\a\_work\1\s\src\libraries\System.Management\tests\System.Management.Tests.csproj::TargetFramework=net11.0-windows]
D:\a\_work\1\s\src\libraries\System.Management\tests\System\Management\ManagementObjectTests.cs(121,54): error IL3050: Using member 'System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. BinaryFormatter serialization uses dynamic code generation, the type of objects being processed cannot be statically discovered. [D:\a\_work\1\s\src\libraries\System.Management\tests\System.Management.Tests.csproj::TargetFramework=net11.0-windows]
D:\a\_work\1\s\src\libraries\System.DirectoryServices\tests\System\DirectoryServices\DirectoryServicesTests.cs(21,31): error IL2026: Using member 'System.Reflection.Assembly.GetTypes()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Types might be removed. [D:\a\_work\1\s\src\libraries\System.DirectoryServices\tests\System.DirectoryServices.Tests.csproj::TargetFramework=net11.0-windows]

For the ManagementObjectTests.cs occurence, mark the method as [RequiresUnreferencedCode("Binary formatter")]

For the DirectoryServicesTests.cs, suppress the warning using #pragma. Add a comment saying "The purpose of the test is to load all types in the assembly. All types that are left is also fine.".

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5e49e977-7ef9-4b3f-ba25-f076d020cb7e

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 21, 2026

@copilot build breaks

...

Fixed in fa2c19f by adding targeted annotations/suppressions for the reported System.Management and System.DirectoryServices analyzer breaks. I verified the affected test projects build and run via /t:test with 0 warnings and 0 errors.

@MichalStrehovsky
Copy link
Copy Markdown
Member

Build breaks in the .NET framework build (TargetFramework=net481).

2026-05-21T08:19:22.2874157Z D:\a\_work\1\s\src\libraries\Microsoft.Extensions.DependencyInjection\tests\DI.External.Tests\SkippableDependencyInjectionSpecificationTests.cs(19,43): error CS0103: The name 'DiagnosticMethodInfo' does not exist in the current context [D:\a\_work\1\s\src\libraries\Microsoft.Extensions.DependencyInjection\tests\DI.External.Tests\Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj::TargetFramework=net481]
2026-05-21T08:19:22.2875350Z D:\a\_work\1\s\src\libraries\Common\tests\SourceGenerators\GeneratorTestHelpers.cs(19,10): error CS0122: 'RequiresUnreferencedCodeAttribute' is inaccessible due to its protection level [D:\a\_work\1\s\src\libraries\Microsoft.Extensions.Configuration.Binder\tests\SourceGenerationTests\Microsoft.Extensions.Configuration.Binder.SourceGeneration.Tests.csproj::TargetFramework=net481]
2026-05-21T08:19:22.2890994Z D:\a\_work\1\s\src\libraries\Common\tests\SourceGenerators\GeneratorTestHelpers.cs(19,10): error CS0122: 'RequiresUnreferencedCodeAttribute' is inaccessible due to its protection level [D:\a\_work\1\s\src\libraries\System.Text.Json\tests\System.Text.Json.SourceGeneration.Unit.Tests\System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj::TargetFramework=net481]
2026-05-21T08:19:22.2892327Z D:\a\_work\1\s\src\libraries\Common\tests\SourceGenerators\GeneratorTestHelpers.cs(19,10): error CS0122: 'RequiresUnreferencedCodeAttribute' is inaccessible due to its protection level [D:\a\_work\1\s\src\libraries\System.Text.Json\tests\System.Text.Json.SourceGeneration.Unit.Tests\System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj::TargetFramework=net481]

Add ifdef for the DiagnosticMethodInfo, include the .cs file with the RequiresUnreferencedCodeAttribute attribute in the test project for the other one.

Also a build break on Windows x64:

src\libraries\System.Net.Http.WinHttpHandler\tests\UnitTests\FakeMarshal.cs(57,20): error IL2091: (NETCORE_ENGINEERING_TELEMETRY=Build) 'T' generic argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicConstructors', 'DynamicallyAccessedMemberTypes.NonPublicConstructors' in 'System.Runtime.InteropServices.Marshal.PtrToStructure<T>(nint)'. The generic parameter 'T' of 'System.Net.Http.Marshal.PtrToStructure<T>(nint)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

For this, propagate the DynamicallyAccessedMembers annotations from the called method to the calling methods T.

@copilot

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/798bad8f-5f09-4037-886d-e162a23c8e96

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 21, 2026 22:05
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 21, 2026

Build breaks in the .NET framework build (TargetFramework=net481).

...

Fixed in ea6ff58. I added the net481 fallback around DiagnosticMethodInfo, linked the shared RequiresUnreferencedCodeAttribute source into the source-generator test projects for .NET Framework, and propagated the PtrToStructure<T> DAM annotations in the WinHttpHandler test fake. Targeted builds now pass; WinHttpHandler /t:test also passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants